<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns="http://www.w3.org/1999/xhtml">
<head lang="en">
    <meta charset="UTF-8">
    <title>智能文本分析及质检系统-修改密码</title>
    <link rel="stylesheet" href="../../assert/css/subpagesCss/forget.css"
          th:href="@{/assert/css/subpagesCss/forget.css}"/>
    <link href="../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css" rel="stylesheet"
          th:href="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/styles/jqx.base.css}"/>
    <link href="../../assert/css/plugin/toastr/toastr.min.css" rel="stylesheet"
          th:href="@{/assert/css/plugin/toastr/toastr.min.css}">
    <link rel="stylesheet" href="../../assert/css/font.css" th:href="@{/assert/css/font.css}"/>
</head>
<body>
<div class="head">
    <img src="../../assert/image/logo.png" th:src="@{/assert/image/logo.png}" alt="">
</div>
<a id="basePath" th:href="@{/}"></a>
<div class="content-box forget_box">
    <div class="box">
        <div class="login_content">
            <div class="tabLogin1">
                <div class="login-box">
                    <div class="tab-title">
                        为了您的账户安全，请先修改初始密码。
                    </div>
                    <form action="#" id="forgetFrom" method="post" class="login-form form-g">
                        <div class="tab-content tab-content1 on">
                            <div class="row_box">
                                <label class="label">登录名</label>
                                <input name="username1" type="text" id="username1" class="userInput"
                                       placeholder="登录名"/><br/>
                            </div>
                            <div class="row_box">
                                <label class="label">手机号</label>
                                <input name="password1" id="phone" type="text" class="userInput" placeholder="手机号"/>
                            </div>
                            <div class="row_box">
                                <label class="label">验证码</label>
                                <input name="code" id="code" type="text" autocomplete="off" class="userInput noTu"
                                       placeholder="请输入验证码" style="width:200px;"/>
                                <span class="code_icon">获取验证码</span>
                            </div>
                            <div class="row_box">
                                <label class="label">设置密码</label>
                                <input type="password" id="loginPwd" placeholder="设置密码" class="userInput"
                                       onkeyup="pwd.pwStrength(this.value)">
                                <ul class="pass_set">
                                    <li id="strength_L">弱</li>
                                    <li id="strength_M">中</li>
                                    <li id="strength_H">强</li>
                                </ul>
                            </div>
                            <div class="row_box">
                                <label class="label">确认密码</label>
                                <input type="password" id="confirmPwd" placeholder="确认密码" class="userInput">
                            </div>
                            <div class="row_box">
                                <label class="label"></label>
                                <button id="save" type="button">确定</button>
                                <a href="">
                                    <button id="closeBtn" type="button">取消</button>
                                </a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="tabLogin2" style="display: none">
                <div class="login-box" id="resultBox">
                    <div style="color:rgb(71, 189, 156)"><span class="fa fa-check-square-o"></span>密码修改成功！</div>
                    <div class="reLogin">请您重新登录，<span class="downNum">3</span>秒后自动跳转登录页面</div>
                    <button type="button" id="backLogin">马上登录</button>
                </div>
            </div>

        </div>
    </div>
</div>
<script src="../../assert/js/jquery.js" th:src="@{/assert/js/jquery.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/plugin/toastr/toastr.min.js"
        th:src="@{/assert/js/plugin/toastr/toastr.min.js}"></script>
<script src="../../assert/js/common.js" th:src="@{/assert/js/common.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/base.js" th:src="@{/assert/js/base.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/jsencrypt.min.js" th:src="@{/assert/js/jsencrypt.min.js(v_=${@commonController.getSysConfigByPK('CACHE_CODE')})}"></script>
<script src="../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxcore.js}"></script>
<script src="../../assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js"
        th:src="@{/assert/js/lib/jqwidgets-ver4.0.0/jqwidgets/jqxvalidator.js}"></script>
<script th:inline="javascript">

    //项目名称
    var basePath = $("#basePath").attr("href");
    /*<![CDATA[*/
    var userName = ""+[[${session[T(com.thinkit.bigdata.web.model.result.Constants).SESSION_USER_INFO].username}]];
    var readonly = ""+[[${session[T(com.thinkit.bigdata.web.model.result.Constants).FIRST_LOGIN]}]];
    $("#username1").val(userName);
    if(readonly!=""){
        $("#username1").attr('readonly', true);
    }
    /*]]>*/
    var forget = {
        num: 60,
        numLogin: 3,
        init: function () {
            forget.initResize();
            forget.backLogin();
            $(window).resize(function () {
                forget.initResize();
            });
            $(".code_icon").on("click", function () {
                if ($(this).attr("disabled")) {
                    return
                }
                forget.hideTip();
                var a = $('#forgetFrom').jqxValidator('validateInput', '#username1');
                var b = $('#forgetFrom').jqxValidator('validateInput', '#phone');
                if(a&&b){
                    forget.downTime($(this)[0]);
                    $.ajax({
                        type: "get",
                        url: basePath + "/rest/user/pass/sendSmsCode",
                        dataType: "json",
                        data: {
                            mobileno: $("#phone").val(),
                            userName: $("#username1").val()
                        },
                        success: function (data) {
                            // 获取验证码可能会失败 所以页面要给出提示--by lihongli 2019/2/23
                            if(data != null && data != "" && data.code == -1){
                                toastrCog.error(data.msg,3000)
                            }
                        }
                    });
                }
            });
            forget.validata();
            $("#save").on("click", function () {
                forget.hideTip();
                $("#forgetFrom").jqxValidator("validate");
            });
            $("#forgetFrom").on("validationSuccess", function (event) {
                // 密码加密 获取公钥
                $.get(basePath + "rest/user/pass/key", function (data) {
                    if(data != ""){
                        var encrypt = new JSEncrypt();
                        encrypt.setPublicKey(data);
                        var inputPass = $("#loginPwd").val();
                        var encrypted = encrypt.encrypt(inputPass);
                        // 保存加密后密码
                        $("#loginPwd").val(encrypted);
                        // 修改密码
                        $.ajax({
                            type: "post",
                            url: basePath + "rest/user/pass/resetPass",
                            dataType: "json",
                            data: {
                                username: $("#username1").val(),
                                mobileno: $("#phone").val(),
                                smscode: $("#code").val(),
                                password: $("#loginPwd").val(),
                            },
                            success: function (data) {
                                if (data.code==0) {
                                    $(".tabLogin1").hide();
                                    $(".tabLogin2").show();
                                    forget.num = 0;
                                    forget.loginDownTime($(".downNum")[0]);
                                } else {
                                    // 给出详细的错误信息 让用户知道为什么失败 --by lihongli 2019/2/23
                                    // toastrCog.error("密码修改失败！",3000);
                                    toastrCog.error(data.msg,3000);
                                    $("#loginPwd").val(inputPass);
                                }
                            }
                        });
                    }
                });
            })

        },
        initResize: function () {
            $(".content-box").height($(window).height() - 100)
        },
        backLogin: function () {
            var url = basePath + "rest/user/logout";
            $("#closeBtn").parent().attr("href", url);
            $(".head img").on("click", function () {
                location.href = url;
            })
            $("#backLogin").on("click", function () {
                location.href = url;
            })
        },
        downTime: function (elem) {
            var timer = null;
            if (forget.num == 0) {
                $(elem).removeAttr("disabled");
                $(elem).html("获取验证码");
                forget.num = 60;
                clearTimeout(timer);
                return;
            } else {
                $(elem).attr("disabled", true);
                $(elem).html(forget.num + "秒后重新获取");
                forget.num--;
            }
            timer = setTimeout(function () {
                forget.downTime(elem)
            }, 1000)
        },
        loginDownTime: function (elem) {
            var timer = null;
            if (forget.numLogin == 0) {
                location.href = basePath + "rest/page/login";
                clearTimeout(timer);
                return;
            } else {
                $(elem).attr("disabled", true);
                $(elem).html(forget.numLogin);
                forget.numLogin--;
            }
            timer = setTimeout(function () {
                forget.loginDownTime(elem)
            }, 1000)
        },
        validata: function () {
            $("#forgetFrom").jqxValidator({
                rules: [
                    {
                        input: '#username1',
                        message: '登录名不能为空!',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#phone',
                        message: '手机号不能为空!',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#code',
                        message: '验证码不能为空!',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#loginPwd',
                        message: '登录密码不能为空!',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#loginPwd',
                        message: '6-30个字符，建议使用字母、数字和符号两种以上的组合!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var val = $(input).val();
                            if ((val && val != "")) {
                                if (!(/^(?![\d]+$)(?![a-zA-Z]+$)(?![^\da-zA-Z]+$).{6,20}$/.test(val))) {
                                    result = false;
                                }
                            }
                            return result;
                        }
                    }
                    , {
                        input: '#loginPwd',
                        message: '两次输入密码不一致!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var val = $(input).val();
                            if($("#confirmPwd").val()!=""){
                                if ((val && val != "")) {
                                    if ($("#confirmPwd").val() != val) {
                                        result = false;
                                    }
                                }
                            }

                            return result;
                        }
                    }
                    , {
                        input: '#confirmPwd',
                        message: '确认密码不能为空!',
                        action: 'keyup,blur',
                        rule: 'required'
                    }
                    , {
                        input: '#confirmPwd',
                        message: '两次输入密码不一致!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var val = $(input).val();
                            if($("#loginPwd").val()!=""){
                                if ((val && val != "")) {
                                    if ($("#loginPwd").val() != val) {
                                        result = false;
                                    }
                                }
                            }

                            return result;
                        }
                    }
                    , {
                        input: '#phone',
                        message: '必须是11位的数字!',
                        action: 'keyup,blur',
                        rule: function (input, commit) {
                            var result = true;
                            var val = $(input).val();
                            if ((val && val != "")) {
                                if (!(/^1[345789]\d{9}$/.test(val))) {
                                    result = false;
                                }
                            }

                            return result;
                        }
                    },
                ],
                hintType: "label",
                onSuccess:function(e){
                }
            });
        },
//        validateCode: function () {
//            $("#forgetFrom").jqxValidator({
//                rules: [
//                    {
//                        input: '#username1',
//                        message: '登录名不能为空!',
//                        action: 'keyup,blur',
//                        rule: 'required'
//                    }
//                    , {
//                        input: '#phone',
//                        message: '手机号不能为空!',
//                        action: 'keyup,blur',
//                        rule: 'required'
//                    }
//                    , {
//                        input: '#phone',
//                        message: '必须是11位的数字!',
//                        action: 'keyup,blur',
//                        rule: function (input, commit) {
//                            var result = true;
//                            var val = $(input).val();
//                            if ((val && val != "")) {
//                                if (!(/^1[34578]\d{9}$/.test(val))) {
//                                    result = false;
//                                }
//                            }
//
//                            return result;
//                        }
//                    },
//                ],
//                hintType: "label"
//            });
//        },
        hideTip: function () {
            $('#forgetFrom').jqxValidator('hideHint', '#username1');
            $('#forgetFrom').jqxValidator('hideHint', '#phone');
            $('#forgetFrom').jqxValidator('hideHint', '#code');
            $('#forgetFrom').jqxValidator('hideHint', '#loginPwd');
            $('#forgetFrom').jqxValidator('hideHint', '#confirmPwd');
        }
    };
    var pwd = {
        checkStrong: function (sPW) {    //返回强度级别
            if (sPW.length <= 4) return 0; //密码太短
            Modes = 0;
            for (i = 0; i < sPW.length; i++) {
                //密码模式
                Modes |= pwd.CharMode(sPW.charCodeAt(i));
            }
            return pwd.bitTotal(Modes);
        },
        CharMode: function (iN) {
            if (iN >= 48 && iN <= 57) //数字
                return 1;
            if (iN >= 65 && iN <= 90) //大写
                return 2;
            if (iN >= 97 && iN <= 122) //小写
                return 4;
            else return 8;
        },
        bitTotal: function (num) {//计算密码模式
            modes = 0;
            for (i = 0; i < 4; i++) {
                if (num & 1) modes++;
                num >>>= 1;
            }
            return modes;
        },
        pwStrength: function (pw) {
            O_color = "#eeeeee";
            L_color = "#ffd8b4";
            M_color = "#ffaf56";
            H_color = "#e85959";
            if (pw == null || pw == '') {
                Lcolor = Mcolor = Hcolor = O_color;
            } else {
                S_level = pwd.checkStrong(pw);
                switch (S_level) {
                    case 0:
                        Lcolor = Mcolor = Hcolor = O_color;
                    case 1:
                        Lcolor = L_color;
                        Mcolor = Hcolor = O_color;
                        break;
                    case 2:
                        Lcolor = L_color;
                        Mcolor = M_color;
                        Hcolor = O_color;
                        break;
                    default:
                        Lcolor = L_color;
                        Mcolor = M_color;
                        Hcolor = H_color;
                }
            }
            $("#strength_L").css('background-color', Lcolor);
            $("#strength_M").css('background-color', Mcolor);
            $("#strength_H").css('background-color', Hcolor);
            return;
        },

    };
    $(function () {
        forget.init();
    });


</script>

</body>
</html>